stage.set_background("moon")
sprite = codesters.Sprite("hedgehog", 0, -210)
score = 0
#my_display = codesters.Display(my_var, x, y)
score_display = codesters.Display(score, -210, -210)
time = 60
#my_display = codesters.Display(my_var, x, y)
time_display = codesters.Display(time, 210, -210)
def left_key():
rotation = sprite.get_rotation()
print(rotation)
sprite.set_rotation(rotation+3)
# add other actions...
stage.event_key("left", left_key)
def right_key():
rotation = sprite.get_rotation()
print(rotation)
sprite.set_rotation(rotation-3)
# add other actions...
stage.event_key("right", right_key)
def interval():
global time
stage.event_interval(interval, 2)
t = codesters.Teacher()
func = t.find_text('interval()')
call = t.find_function('event_interval')
minus = t.find_text('-=')
updates = t.get_parameters_for_function('update')
updates_text = t.find_text('update')
try:
def_line = int(func[0][0])
def_line_indent = t.get_indent_at_line(def_line)
except:
def_line = -1
def_line_indent = -1
try:
call_line = int(call[0][0])
call_line_indent = t.get_indent_at_line(call_line)
except:
call_line = -1
call_line_indent = -1
try:
tval2a = int(minus[0][0])
tval2b = t.get_indent_at_line(tval2a)
tval2c = minus[0][1].replace(" ", '')
except:
tval2a = -1
tval2b = -1
tval2c = "DNE"
try:
tval3a = int(updates_text[0][0])
tval3b = t.get_indent_at_line(tval3a)
tval3c = updates[0][0]
except:
tval3a = -1
tval3b = -1
tval3c = "DNE"
t1 = TestObjective()
t1.add_success(tval2a != -1 and tval2b == 4 and tval2c == "time-=1" and def_line <tval2a < call_line, "Great job!")
t1.add_failure(tval2a == -1, "Did you add Subtract Value to your event?")
t1.add_failure(tval2a != -1 and tval2c != "time-=1", "Did you subtract 1 from time correctly?")
t1.add_failure(tval2b < 4, "Make sure your -= command is indented 4 spaces in your interval event.")
t1.add_failure(tval2b > 4, "Make sure your -= command is indented only 4 spaces inside your interval event.")
t1.add_failure(not (def_line <tval2a < call_line), "Make sure your -= command is inside your interval event.")
t2 = TestObjective()
t2.add_success(tval3a != -1 and tval3b ==4 and tval3c == 'time' and def_line <tval3a < call_line, "Great job!")
t2.add_failure(tval3a == -1, "Did you add Update Display to your event?")
t2.add_failure(tval3a != -1 and tval3c != "time", "Did you update time_display with the time variable?")
t2.add_failure(tval3b < 4, "Make sure your .update() command is indented 4 spaces in your interval event.")
t2.add_failure(tval3b > 4, "Make sure your .update() command is indented only 4 spaces inside your interval event.")
t2.add_failure(not (def_line <tval3a < call_line), "Make sure your .update() command is inside your interval event.")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)